#include <iostream>
#include <gtest/gtest.h>

using namespace std;

class MyTest : public testing::Test // 独立测试套件
{
public:
    virtual void SetUp() override
    {
        cout << "单元测试前执行环境初始化" << endl;
        data = 0;
    }
    virtual void TearDown() override
    {
        cout << "单元测试后执行环境清理" << endl;
        data = 1000;
    }
    int data = 1;
};

TEST_F(MyTest, test1) // 1.TEST_F  2.必须对应到套件类名，才能访问成员
{
    cout << "data:" << data << endl;
    data = 10;
    cout << "data:" << data << endl; // 每一个单元测试都有独立的成员数据，互不影响
}

TEST_F(MyTest, test2)
{
    cout << "data:" << data << endl;
    data = 100;
    cout << "data:" << data << endl;
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    RUN_ALL_TESTS();
    return 0;
}